package com.smyh.model.tableModel;

import android.content.Context;
import android.graphics.Color;
import android.text.InputType;
import android.view.Gravity;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/*
 * 添加内容
 */
public class AddContentsRow  {


    public static TableRow addTableRow(Context context,String[] strings,Integer integer) {

        TableRow tableRow = new TableRow(context);
        tableRow.setLayoutParams(new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));

        for (int i = 0; i < strings.length; i++) {
            TableRow.LayoutParams params = new TableRow.LayoutParams(
                    TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT);
                params.leftMargin = KtableView. lineWidth;
                params.topMargin = KtableView. lineWidth;
                params.weight =1;
                if(integer!=null){
                    EditText  editView = new EditText(context);
                    if(integer!=i){
                        editView.setEnabled(false);
                    }
                    editView.setGravity(Gravity.CENTER );
                    editView.setBackgroundColor(Color.WHITE);
                    editView.setInputType(InputType.TYPE_CLASS_NUMBER);
                    editView.setLayoutParams(params);
                    editView.setTextSize(13);
                    editView.setTextColor(Color.GRAY);
                    editView.setText(strings[i]);
                    tableRow.addView(editView);
                }else{
                    TextView textView = new TextView(context);
                    textView.setGravity(Gravity.CENTER );
                    textView.setBackgroundColor(Color.WHITE);
                    textView.setPadding(8,8,8,8);
                    textView.setLayoutParams(params);
                    textView.setSingleLine(false);
                    textView.setMaxEms(10);
                    textView.setTextSize(13);
                    textView.setText(strings[i]);
                    tableRow.addView(textView);
                }

        }
        return tableRow;

    }

}